package gui.panel;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.ScrollPane;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import network.NetworkInterface;
import listeners.SendListener;


public class ConversationPanel extends JPanel {

	private JTextArea txtChatHistory;
	private JTextField txtMessageToSend;
	private JList listInterlocutors;
	private JButton btnSendMessage;
	
	private NetworkInterface networkInterface;
	
	public ConversationPanel(NetworkInterface networkInterface) {
		super(new BorderLayout());
		this.networkInterface = networkInterface;
		this.initComponents();
	}

	private void initComponents() {
		// TODO Auto-generated method stub
		this.txtChatHistory = new JTextArea(50, 50);
		this.txtMessageToSend = new JTextField(20);
		this.listInterlocutors = new JList(new DefaultListModel());
		this.btnSendMessage = new JButton("Send");
				
		this.txtChatHistory.setLineWrap(true);
		this.txtChatHistory.setWrapStyleWord(true);
		this.txtChatHistory.setEditable(false);
		
		// TODO Remove this example
		//((DefaultListModel)(this.listInterlocutors.getModel())).addElement("eliott@geitp109-9");
		
		this.addComponents();
		this.addListeners();
	}

	private void addComponents() {
		// TODO Auto-generated method stub
		JPanel panCenter = new JPanel(new BorderLayout());
		JPanel panMsgToSend = new JPanel(new FlowLayout());
		panMsgToSend.add(this.txtMessageToSend);
		panMsgToSend.add(this.btnSendMessage);
		panCenter.add(new JScrollPane(this.txtChatHistory, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);
		panCenter.add(panMsgToSend, BorderLayout.SOUTH);
		this.add(panCenter, BorderLayout.CENTER);
		this.add(new JScrollPane(this.listInterlocutors), BorderLayout.EAST);
	}

	private void addListeners() {
		this.btnSendMessage.addActionListener(new SendListener(this.networkInterface, this));
	}
	
	public JTextArea getTxtChatHistory() {
		return txtChatHistory;
	}

	public void setTxtChatHistory(JTextArea txtChatHistory) {
		this.txtChatHistory = txtChatHistory;
	}

	public JTextField getTxtMessageToSend() {
		return txtMessageToSend;
	}

	public void setTxtMessageToSend(JTextField txtMessageToSend) {
		this.txtMessageToSend = txtMessageToSend;
	}

	public JList getListInterlocutors() {
		return listInterlocutors;
	}

	public void setListInterlocutors(JList listInterlocutors) {
		this.listInterlocutors = listInterlocutors;
	}

	public JButton getBtnSendMessage() {
		return btnSendMessage;
	}

	public void setBtnSendMessage(JButton btnSendMessage) {
		this.btnSendMessage = btnSendMessage;
	}
	
	
	
}
